package com.hzqy.persistence.dao.wchat;


import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.hzqy.commons.utils.SessionKey;
import com.hzqy.commons.utils.SystemConfigUtils;
import com.hzqy.web.vo.wchat.LoginMessage.ReceiveMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.hzqy.persistence.dao.core.PersistenceDao;
import com.hzqy.web.vo.PmsUserVo;
import com.hzqy.web.vo.system.SysConfigVo;

import static java.lang.Integer.parseInt;


@Repository
public class WchatWXDao extends PersistenceDao<PmsUserVo, Integer>{

	protected final Logger LOG = LoggerFactory.getLogger(WchatWXDao.class);
	
	public String selectTokenByKey(SysConfigVo config){
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("f_sc_key", config.getF_sc_key());
		return getSqlSession().selectOne(this.getNamespace() + "selectTokenByKey", map);
	}
	public Integer insertRSMS(ReceiveMessage vo){
		return getSqlSession().insert(this.getNamespace() + "insertRSMS", vo);
	}
	public ReceiveMessage selectRSMS(ReceiveMessage vo){
		return getSqlSession().selectOne(this.getNamespace() + "selectRSMS", vo);
	}

	public Integer updateRSMS(ReceiveMessage vo){
		String time = SystemConfigUtils.getSysConfig("SMS_verification_time");
		int times = parseInt(time, 10);
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date = new Date();
		vo.setStartTime(df.format(date));
		Date endTime = new Date(date.getTime() + times*60*1000);
		vo.setEndTime(df.format(endTime));
		return getSqlSession().update(this.getNamespace() + "updateRSMS", vo);
	}

	public Integer selectRSMSCount(ReceiveMessage vo){
		return getSqlSession().selectOne(this.getNamespace() + "selectRSMSCount", vo);
	}

}
